package com.pri.chat.adapter;

import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.netease.nim.uikit.net.SharedHelper;
import com.netease.nim.uikit.net.entity.WishListBean;
import com.pri.chat.R;
import com.pri.chat.activity.NetPicShowActivity;
import com.pri.chat.utils.FriendsCircleImageLayout;
import com.pri.chat.utils.GlideUtil;
import com.pri.chat.utils.StringUtils;
import com.pri.chat.utils.TimeUtils;
import com.vondear.rxtool.RxActivityTool;

import java.io.Serializable;
import java.util.List;

/**
 * 描述：添加类的描述
 *
 * @author
 * @time 2020/5/9
 */
public class OtherWishAdapter extends BaseQuickAdapter<WishListBean, BaseViewHolder> {
    private OnImageClickListener mOnImageClickListener;
    public void setOnImageClickListener( OnImageClickListener listener) {
        mOnImageClickListener = listener;
    }
    public interface OnImageClickListener {

        void onItemClick(View view, int c_pos, int f_pos);
    }
    public OtherWishAdapter(int layoutResId, @Nullable List<WishListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, WishListBean item) {
        helper.addOnClickListener(R.id.tv_wish_go);
        helper.addOnClickListener(R.id.iv_logo);
        helper.addOnClickListener(R.id.iv_share);
        ImageView tv_wish_finish = helper.getView(R.id.tv_wish_finish);
        TextView tv_wish_go = helper.getView(R.id.tv_wish_go);
        if(item.getMemberId().equals(SharedHelper.readId(mContext))){
            if(item.getStatus()==0){
                helper.setText(R.id.tv_wish_go,"完成愿望");
                helper.setVisible(R.id.tv_wish_go,true);
                tv_wish_finish.setVisibility(View.GONE);
            }else{
                helper.setVisible(R.id.tv_wish_go,false);
                tv_wish_finish.setVisibility(View.VISIBLE);
            }
        }else{
            if(item.getStatus()==0){
                helper.setText(R.id.tv_wish_go," 帮TA完成 ");
                helper.setVisible(R.id.tv_wish_go,true);
                if(item.getCanHelp() != 0){
                    tv_wish_go.setBackgroundResource(R.drawable.btn_gray_20_shape);
                }else{
                    tv_wish_go.setBackgroundResource(R.drawable.btn_orange_shape);
                }
                tv_wish_finish.setVisibility(View.GONE);
            }else{
                helper.setVisible(R.id.tv_wish_go,false);
                tv_wish_finish.setVisibility(View.VISIBLE);
            }
        }

        View sexLinear = helper.getView(R.id.sex_bg);
        ImageView sexLogo = helper.getView(R.id.sex_logo);
        if(item.getSex().equals("男")){
            sexLogo.setImageResource(R.mipmap.man);
            sexLinear.setBackgroundResource(R.drawable.btn_sex_man);
        }else{
            sexLogo.setImageResource(R.mipmap.woman);

            sexLinear.setBackgroundResource(R.drawable.btn_sex_woman);
        }
        TextView vip_bg = helper.getView(R.id.vip_bg);
        if("是".equals(item.getMemberLevel())){
            vip_bg.setVisibility(View.VISIBLE);
            vip_bg.setText("VIP");
        }else{
            vip_bg.setVisibility(View.GONE);
        }
        TextView vip_super_bg = helper.getView(R.id.vip_super_bg);
        if("是".equals(item.getSuperVip())){
            vip_super_bg.setText("SVIP");
            vip_super_bg.setVisibility(View.VISIBLE);
        }else{
            vip_super_bg.setVisibility(View.GONE);
        }


        helper.setText(R.id.tv_wish_age,item.getAge()+"");
        helper.setText(R.id.tv_wish_name,item.getMemberName());
        helper.setText(R.id.tv_wish_desc, Html.fromHtml((StringUtils.isEmpty(item.getBiaoqian()) ?"":"<font color='#A396F5'>"+item.getBiaoqian()+"</font> ")+item.getContent()));
        String cInfo = "";
        if(!StringUtils.isEmpty(item.getCity())){
            cInfo = "·"+item.getCity();
        }
        helper.setText(R.id.time_address_look, TimeUtils.computeFromNowStr(item.getAddDate())+cInfo);
        GlideUtil.getInstance().loadHeadImg(mContext,helper.getView(R.id.iv_logo),item.getHeadPic());
        ImageView imageView = helper.getView(R.id.item_image);
        Glide.with(mContext)
                .load(item.getPicList())
                .centerCrop()
                .into(imageView);

        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                bundle.putInt("item",0);
                bundle.putSerializable("listPath",(Serializable) item.getImgs());
                RxActivityTool.skipActivity(mContext, NetPicShowActivity.class,bundle);

            }
        });
    }
}
